﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Data;
using DotNet.Model;
using DotNet.Common;
using System.Data;
namespace DotNet.Business
{
    /// <summary>
    /// 产品，缓存数据列表 countByClass
    /// 分页，按ID查询不能缓存
    /// </summary>
    public class productBll
    {
        productDal pDal = new productDal();
        #region 是否存在该记录
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int productId)
        {
            return pDal.Exists(productId);
        }
        #endregion

        #region 是否存在产品型号---郑同飞
        /// <summary>
        /// 是否存在产品型号---郑同飞
        /// </summary>
        /// <param name="proModel"></param>
        /// <returns></returns>
        public bool Exists(string proModel)
        {
            return pDal.Exists(proModel);
        }
        #endregion

        #region 查询每个类别下面的产品根据类别号
        /// <summary>
        /// 是否存在该记录,
        /// 缓存，查询次数较多。
        /// </summary>
        public int countByClass(int pclassid)
        {
            string CKey = "Product_" + pclassid;
            if (!CacheUtil.IsExist(CKey))
            {
                CacheUtil.Insert(CKey, pDal.countByClass(pclassid),60);
            }
            return Convert.ToInt32(CacheUtil.Read(CKey));
        }
        #endregion

        #region 获得产品数据列表
        /// <summary>
        /// 获得产品数据列表
        /// </summary>
        /// <returns></returns>
        public IList<product> GetModel()
        {
            return pDal.GetModel();
        }
        #endregion

        #region 获得产品数据表
        /// <summary>
        /// 获得产品数据表
        /// </summary>
        /// <returns></returns>
        public DataTable getDataTable()
        {
            return pDal.getDataTable();
        }
        #endregion

        #region 根据产品号查询实体
        /// <summary>
        /// 根据产品号查询实体
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public product GetModel(int productId)
        {
            return pDal.GetModel(productId);
        }
        #endregion

        #region 根据关联标识id获得数据
        /// <summary>
        /// 根据关联标识id获得数据
        /// </summary>
        /// <param name="mark"></param>
        /// <param name="count"></param>
        /// <param name="productId"></param>
        /// <returns></returns>
        public DataTable GetModelByMark(int mark,int count,int productId)
        {
            return pDal.GetModelByMark(mark,productId,count);
        }
        #endregion

        #region 修改产品
        /// <summary>
        /// 修改产品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(product model)
        {
            CacheUtil.RemoveByRegexp(@"Product_.?");
            return pDal.Update(model);
        }
        #endregion

        #region 快速推荐
        public bool isBast(bool bo, int id)
        {
            return pDal.isBast(bo, id);
        }
        #endregion

        #region 快速屏蔽
        public bool isCan(bool bo, int id)
        {
            return pDal.isCan(bo, id);
        }
              #endregion

        #region 最新设置
        public bool IsNew(bool bo, int id)
        {
            return pDal.IsNew(bo, id);
        }
        #endregion

        #region 首页显示
        public bool isIndex(bool bo, int id)
        {
            return pDal.isIndex(bo, id);
        }
        #endregion

        #region 快速修改产品
        /// <summary>
        /// 快速修改产品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool updateFast(product model)
        {
            CacheUtil.RemoveByRegexp(@"Product_.?");
            return pDal.updateFast(model);
        }
        #endregion

        #region 批量产品根据产品号
        /// <summary>
        /// 批量移动产品类别根据产品父类别号
        /// </summary>
        /// <param name="id">产品号</param>
        ///  <param name="classid">要移动到的类别号</param>
        /// <returns></returns>
        public bool Update(string[] id, string classid)
        {
            CacheUtil.RemoveByRegexp(@"Product_.?");
            return pDal.Update(id, classid);
        }
        #endregion

        #region 删除产品根据产品号
        /// <summary>
        /// 删除产品根据产品号
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public bool Delete(int productId)
        {
            CacheUtil.RemoveByRegexp(@"Product_.?");
            return pDal.Delete(productId);
        }
        #endregion

        #region 批量删除产品根据产品号
        /// <summary>
        /// 批量删除产品根据产品号
        /// </summary>
        /// <param name="pId"></param>
        /// <returns></returns>
        public bool Delete(string[] pId)
        {
            CacheUtil.RemoveByRegexp(@"Product_.?");
            return pDal.Delete(pId);
        }
        #endregion

        #region 添加产品
        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Insert(product model)
        {
            CacheUtil.RemoveByRegexp(@"Product_.?");
            return pDal.Insert(model);
        }
        #endregion

        #region 后台产品分页      
        /// <summary>
        /// 后台产品分页--类别，关键字
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="classid">类别</param>
        /// <param name="key">关键字</param>
        /// <returns></returns>
        public DataTable pagingForProduct(int pageIndex, int pageSize, int classid, string key)
        {
            if (classid == 0 && key == "")
            {
                return pDal.pagingForProduct(pageIndex, pageSize);
            }
            else if (classid == 0 && key != "")
            {
                return pDal.pagingForProduct(pageIndex, pageSize, key);
            }
            else if (classid > 0 && key == "")
            {
                return pDal.pagingForProduct(pageIndex, pageSize, classid);
            }
            else
                return pDal.pagingForProduct(pageIndex, pageSize, classid, key);
        }
        #endregion

        #region 后台屏蔽产品分页
        /// <summary>
        /// 后台屏蔽产品分页---郑同飞
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="isCan">是否屏蔽（屏蔽：true,不屏蔽：false）</param>
        /// <returns></returns>
        public DataTable pagingForProduct(int pageIndex, int pageSize, bool isCan) 
        {
            return pDal.pagingForProduct(pageIndex, pageSize, isCan);
        }
        #endregion

        #region "前台产品分页 "
        public IList<product> pagingForProduct(int pageIndex, int pageSize,int classid,int ptype,bool iscan)
        {

            return pDal.pagingForProduct(pageIndex, pageSize, classid,ptype,iscan);
        }
        #endregion

        #region 获得产品总数
        /// <summary>
        /// 获得产品数类别和关键字为空（用空字符串表示如：“”）
        /// </summary>
        /// <param name="classid">类别</param>
        /// <param name="where">关键字</param>
        /// <returns></returns>
        public int getRecordCount(int classid,string where)
        {
            if (classid == 0 && where == "")
            {
                return pDal.getRecordCount(false);
            }
            else if (classid == 0 && where != "")
            {
                return pDal.getRecordCount(where);
            }
            else if (classid > 0 && where == "")
            {
                return pDal.getRecordCount(classid);
            }
            else
                return pDal.getRecordCount(classid, where);
        }
        #endregion

        #region 获得后台屏蔽产品总数
        /// <summary>
        /// 获得后台屏蔽产品总数
        /// </summary>
        /// <param name="isCan">是否屏蔽</param>
        /// <returns></returns>
        public int getRecordCount(bool isCan)
        {
            return pDal.getRecordCount(isCan);
        }
        #endregion

        #region 获得前台产品总数
        /// <summary>
        /// 
        /// </summary>
        /// <param name="classid"></param>
        /// <param name="ptype">1,推荐2,首页展示，3,热门,4最新</param>
        /// <param name="iscan"></param>
        /// <returns></returns>
        public int getRecordCount(int classid,int ptype,bool iscan)
        {
           
            return pDal.getRecordCount(classid, ptype,iscan);
        }
        #endregion

        #region 随机数
        public DataTable getRandomProduct(int num)
        {
            return pDal.getRandomProduct(num);
        }
        #endregion

        #region 产品类型
          /// <summary>
          /// 产品类型
          /// 1,推荐
          /// 2,首页展示，
          /// 3,热门
          /// </summary>
          /// <param name="num">数量</param>
          /// <param name="type">1,推荐2,首页展示，3,热门</param>
          /// <returns></returns>
        public DataTable getTypeProduct(int num, int type)
        {
            return pDal.getTypeProduct(num, type);
        }
        #endregion

        #region 获取指定靠前的产品---郑同飞
        /// <summary>
        /// 获取指定靠前的产品---郑同飞
        /// </summary>
        /// <param name="productCount"></param>
        /// <param name="classid">产品类别（当类别为0时，获取所有的类的产品）</param>
        /// <returns></returns>
        public DataTable getProductBefor(int productCount,int classid)
        {
           
                return pDal.getProductBefor(productCount, classid);
            
        }
        #endregion

        #region 得到最新的产品---郑同飞
        public DataTable getNewProduct()
        {
            return pDal.getNewProduct();
        }
        #endregion

        #region 根据产品id集合获得数据---郑同飞
        /// <summary>
        /// 根据产品id集合获得数据---郑同飞
        /// </summary>
        /// <param name="productids"></param>
        /// <returns></returns>
        public IList<product> GetModel(string[] productids) 
        {
            return pDal.GetModel(productids);
        }
        #endregion
    }
}
